//
//  UITextField+RACTools.m
//  Demo
//
//  Created by lx on 2019/3/27.
//  Copyright © 2019 mgz. All rights reserved.
//

#import "UITextField+RACTools.h"

@implementation UITextField (RACTools)

- (RACSignal *)rac_textMaxLength:(int)length{
    @weakify(self);
    return [[[[[RACSignal
                defer:^{
                    @strongify(self);
                    return [RACSignal return:self];
                }]
               concat:[self rac_signalForControlEvents:UIControlEventEditingChanged]]
              map:^(UITextField *x) {
                  return x.text = x.text.length >= length ? [x.text substringToIndex:length] : x.text;
              }]
             takeUntil:self.rac_willDeallocSignal]
            setNameWithFormat:@"%@ -rac_textMaxLength", [self rac_description]];
}


- (void)textMaxLength:(int)length{
    [[self rac_textMaxLength:length] subscribeNext:^(id x) {
        
    }];
}

@end
